const express = require("express");
const router = express.Router();
const ManageModule = require("../../../api/mange/manage");
const AuthModule = require("../../../api/auth");
// 锁定用户
router.post("/LockUser", (req, res) => {
  ManageModule.LockUser(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 取消锁定用户
router.post("/cancelLockUser", (req, res) => {
  ManageModule.UnlockUser(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 添加用户
router.post("/addUser", (req, res) => {
  let ip = req.ip;
  let agentInfo = req.userAgentInfo;
  let { isWindows, isMobile } = agentInfo;
  let device = null;
  if (isWindows) {
    device = 1;
  } else if (isMobile) {
    device = 0;
  } else {
    device = null;
  }
  registerModule({
    ...req.body,
    type: 1,
    register_ip: ip,
    register_device: device,
  })
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 黑名单列表
router.get("/Blacklist", (req, res) => {
  ManageModule.Blacklist(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 拉黑
router.post("/ToBlack", (req, res) => {
  ManageModule.ToBlack(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 取消拉黑
router.post("/CancelBlack", (req, res) => {
  ManageModule.CancelBlack(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 设置超级管理员
router.post("/SetSuperUser", (req, res) => {
  ManageModule.SetSuperUser(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取用户列表
router.get("/list", (req, res) => {
  ManageModule.userList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取用户信息
router.get("/info", (req, res) => {
  ManageModule.GetUserBaseInfo(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 修改基本信息
router.post("/UpdateBaseInfo", (req, res) => {
  ManageModule.UpdateUserBaseInfo(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取用户token列表
router.get("/getUserTokenList", (req, res) => {
  ManageModule.UserKeysList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除用户token
router.post("/removeUserToken", (req, res) => {
  ManageModule.DeleteUserKeys(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 清空用户token
router.post("/EmptyUserKeysList", (req, res) => {
  ManageModule.EmptyUserKeysList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取用户行为列表 (已完成)
router.get("/getUserActiveList", (req, res) => {
  let { user } = req.query;
  getActiveList({ user })
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除用户行为日志 (已完成)
router.post("/removeUserActive", (req, res) => {
  let { user, id } = req.body;
  removeActive({ user, id })
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 清空用户行为日志 (已完成)
router.post("/emptyUserActive", (req, res) => {
  let { user, id } = req.body;
  emptyUserActive({ user, id })
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 修改用户角色
router.get("/changeRole", (req, res) => {});
// 重置用户密码
router.post("/ResetUserPassword", (req, res) => {
  ManageModule.ResetUserPassword(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 限制用户登录
router.post("/restrictLogin", (req, res) => {
  let { user, duration } = req.body;
  restrictLoginModule({ user, duration })
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 取消限制登录
router.post("/cancelRestrictLogin", (req, res) => {
  let { user } = req.body;
  cancelRestrictLoginModule({ user })
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取用户地址库 (已完成)
router.get("/userAddressList", (req, res) => {
  let { user } = req.query;
  req.$user = user;
  ManageModule.GetUserAddressList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 修改用户地址库 (已完成)
router.post("/updateUserAddress", (req, res) => {
  updateUserAddress(req.body)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 设置用户默认地址
router.post("/SetUserDefaultAddress", (req, res) => {
  ManageModule.SetUserDefaultAddress(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除用户地址库 (已完成)
router.post("/removeUserAddress", (req, res) => {
  ManageModule.DeleteUserAddress(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 清空用户地址库 (已完成)
router.get("/emptyUserAddress", (req, res) => {
  let { user } = req.body;
  emptyUserAddress({ user })
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除用户
router.post("/remove", (req, res) => {
  ManageModule.DeleteUser(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取用户设备列表
router.get("/GetUserDeviceList", (req, res) => {
  ManageModule.GetUserDeviceList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除用户设备
router.post("/DeleteUserDevice", (req, res) => {
  ManageModule.DeleteUserDevice(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 设置用户默认设备
router.post("/SetDefaultDevice", (req, res) => {
  ManageModule.SetDefaultDevice(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 发布通知
router.post("/PublishNotice", (req, res) => {
  ManageModule.PublishNotice(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除通知
router.post("/DeleteNotice", (req, res) => {
  ManageModule.DeleteNotice(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 通知列表
router.get("/NoticeList", (req, res) => {
  ManageModule.NoticeList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 查看通知详情
router.get("/NoticeDetail", (req, res) => {
  ManageModule.NoticeDetail(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取账号注销状态
router.get("/GetUserLogoffStatus", (req, res) => {
  ManageModule.GetUserLogoffStatus(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 注销列表
router.get("/LogoffList", (req, res) => {
  ManageModule.LogoffList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 同意注销
router.post("/AgreeLogoff", (req, res) => {
  ManageModule(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 拒绝注销
router.post("/RefuseLogoff", (req, res) => {
  ManageModule.RefuseLogoff(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取角色列表
router.get("/GetRoleList", (req, res) => {
  ManageModule.GetUserRoleList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 获取用户类型列表
router.get("/GetUserTypeList", (req, res) => {
  ManageModule.GetUserTypeList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除用户类型
router.post("/DeleteUserType", (req, res) => {
  ManageModule.DeleteUserType(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 创建用户类型
router.post("/CreateUserType", (req, res) => {
  ManageModule.CreateUserType(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 修改用户类型
router.post("/UpdateUserType", (req, res) => {
  ManageModule.UpdateUserType(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});

// 获取运维数据
router.get("/Observe", (req, res) => {
  ManageModule.Observer(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 漂流瓶列表
router.get("/GetDriftList", (req, res) => {
  ManageModule.GetDriftList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除漂流瓶
router.post("/DeleteDrift", (req, res) => {
  ManageModule.DeleteDrift(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 频道列表
router.get("/ChannelList", (req, res) => {
  ManageModule.ChannelList(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 创建频道
router.post("/CreateChannel", (req, res) => {
  ManageModule.CreateChannel(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 删除频道
router.post("/DeleteChannel", (req, res) => {
  ManageModule.DeleteChannel(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
// 修改频道
router.post("/UpdateChannel", (req, res) => {
  ManageModule.UpdateChannel(req)
    .then((r) => res.send(r))
    .catch((e) => res.send(e));
});
module.exports = router;
